package com.i.picservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.i.piccommon.domain.Category;
import com.i.piccommon.domain.PhotoGraph;
import com.i.picservice.mapper.PhotoGraphMapper;
import com.i.picservice.service.IPhotoGraphService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author lewis
 * @type class
 * @description
 * @since 2024/10/25
 */
@Service
@RequiredArgsConstructor
public class PhotoGraphServiceImpl extends ServiceImpl<PhotoGraphMapper, PhotoGraph> implements IPhotoGraphService {
    private final PhotoGraphMapper mapper;
    @Override
    public Boolean uploadImage(PhotoGraph photoGraph) {
        return null;
    }
    @Override
    public PhotoGraph selectOneByPhoto(Integer pid) {
        return mapper.selectOneByPhoto(pid);
    }
    @Override
    @Transactional
    public void insertByPhotoCS(List<Map<String, Integer>> list) {
        list.forEach(mapper::insertByPhotoCS);
    }
    @Override
    public Integer selectIdByUrl(String url) {
        PhotoGraph photoGraph = lambdaQuery().eq(PhotoGraph::getUrl,url).one();
        return photoGraph.getPid();
    }
    @Override
    public IPage<PhotoGraph> getPage(Category vo) {
        Page<PhotoGraph> page = new Page<>();
        page.setCurrent(vo.getCurrentPage());
        page.setSize(vo.getPageSize());
        return mapper.selectPage(page,null);
    }
}

